#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
#define NUM 16
const char*myfile="./mycmd";
//const char *myfile="/home/zhenbailinzi/2023code/test0115/mycmd";
int main()
{
    char*const _env[NUM]={
       (char*)"ZHEN_VAL=11223344",
        NULL
    };
    pid_t id =fork();
    //int a=0;
    if(id==0)
    {
        //子进程
        printf("子进程开始运行，pid:%d\n",getpid());
        sleep(3);
        char*const _argv[NUM]={
           (char*)"ls",
           (char*)"-a",
           (char*)"-l",
            NULL
        };
        //execl("/usr/bin/ls","ls","-a","-l",NULL);
        //execv("/usr/bin/ls",_argv);
        //execlp("ls","ls","-a","-l",NULL);
        //execvp("ls",_argv);
        //execl(myfile,"ls","-a",NULL);
        //execlp("bash","bash","test.sh",NULL);
        //execlp("python","python","test.py",NULL);
        //execlp("bash","bash","test.sh",NULL);
        //execlp("./test.py","test.py",NULL);
        execle(myfile,"mycmd","-a",NULL);
        exit(1);
        //a=1;
    }
    else
    {
        //父进程
        printf("父进程开始运行，pid:%d\n",getpid());
        int status =0;
        pid_t id =waitpid(-1,&status,0);
        if(id>0)
        {
           printf("wait success,exit code:%d\n",WEXITSTATUS(status));
        }
        //a=2;
    }
    //printf("%d\n",a);
    return 0;
}
